package edu.wuster.blog.mapper;

import edu.wuster.blog.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Insert("insert into user (username,password,gender,phone,id_number,create_time) values(#{username},#{password},#{gender},#{phone},#{idNumber},#{createTime})")
    void addUser(User user);

    @Select("select username from user where username = #{username} and is_delete = 0")
    User selectByUsername(User user);

    @Select("select * from user where user.username = #{username} and user.phone=#{phone} and user.id_number=#{idNumber} and is_delete = 0")
    User lossPassword(User user);

    @Update("update user set password = '123456' where username = #{username}")
    void resetPassword(User user);

    @Select("select * from user where id = #{id} and is_delete = 0")
    User selectById(Integer id);

    @Update("update user set gender = #{gender}, phone = #{phone}, id_number = #{idNumber} where id = #{id} and is_delete = 0")
    void resetById(User user);

    @Update("update user set password = #{password} where id = #{id}")
    void setNewPassword(User user);

    @Update("update user set is_delete = 1 where id = #{id}")
    void deleteUser(Integer id);

    @Select("select * from user where is_delete = 0 and username = #{username} and password = #{password}")
    User selectLogin(User user);
}
